package com.yanqu.road.dao.dbV2.serializer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class DObject extends Serializer<Object>{
    @Override
    public Object deserialize(Object object, Field field) {
        Type genericType = field.getGenericType();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String s = (String) object;
            Object o = objectMapper.readValue(s, new DType<Object>(genericType){});
            return o;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Object serialize(Object o) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(o);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String SqlType() {
        return "MEDIUMTEXT";
    }

    @Override
    public Object defaultValue() {
        return "";
    }
}
